package com.zhxy.gis;

import java.io.Serializable;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.junit.Test;

import com.zhxy.gis.BaiduCoordinateEncryption;
import com.zhxy.gis.CoordinateEncryptionListener;
import com.zhxy.gis.Location;

public class BaiduCoordinateEncryptionTestCase {
	
	@Test
	public void test() throws Exception {
		
		ThreadPoolExecutor exe = new ThreadPoolExecutor(1, 1, 1000, 
				TimeUnit.DAYS, 
				new LinkedBlockingQueue<Runnable>());
		
		BaiduCoordinateEncryption ce = new BaiduCoordinateEncryption();
		ce.setConnectionCount(1);
		//ce.setWaitBy(3000);
		ce.setExecutorService(exe);
		ce.addCoordinateEncryptionListener(new CoordinateEncryptionListener() {
			
			@Override
			public void error(Location location, Object o) {
				System.out.println("!!!err! old=" + location);
			}
			
			@Override
			public void complete(Location oldLocation, Location newLocation,
					Object o) {
				System.out.println("old=" + oldLocation + ",new" + newLocation);
			}
		});
		ce.init();
		
		long begin = System.currentTimeMillis();
		
		for (int i = 0; i < 5; i++) {
			ce.encrypt(new Location(40, 110), null);
		}
		exe.shutdown();
		exe.awaitTermination(1000, TimeUnit.DAYS);
		
		System.err.println(System.currentTimeMillis() - begin);
	}
}
